package com.ruoyi.ly.controller;


import com.ruoyi.ly.domain.dto.PageSpaceMeetingDTO;
import com.ruoyi.ly.domain.dto.SpaceMeetingAddDTO;
import com.ruoyi.ly.domain.dto.SpaceMeetingUpdateDTO;
import com.ruoyi.ly.domain.vo.SpaceMeetingVO;
import com.ruoyi.ly.service.SpaceMeetingService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "功能场地接口")
@RequestMapping("/meeting")
@Slf4j
public class SpaceMeetingController {

    @Autowired
    private SpaceMeetingService spaceMeetingService;

    //  新增功能场地信息
    @PostMapping("/add")
    @ApiOperation(value = "新增功能场地信息")
    public Result<String> insert(@RequestBody SpaceMeetingAddDTO SpaceMeetingDTO){
        log.info("新增功能场地信息");
        spaceMeetingService.save(SpaceMeetingDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询功能场地信息")
    public Result<PageResult> page(PageSpaceMeetingDTO pageSpaceMeetingDTO) {
        log.info("分页查询：{}", pageSpaceMeetingDTO);
        PageResult pageResult = spaceMeetingService.pageQuery(pageSpaceMeetingDTO);
        return Result.success(pageResult);
    }

    //删除功能场地
    @DeleteMapping("/delete/{meetId}")
    @ApiOperation(value = "删除功能场地")
    public Result delete(@PathVariable("meetId")Long meetId) {
        log.info("删除功能场地：{}", meetId);
        spaceMeetingService.delete(meetId);
        return Result.success();
    }

    //修改功能场地
    @PutMapping("/update")
    @ApiOperation(value = "修改功能场地")
    public Result update(@RequestBody SpaceMeetingUpdateDTO SpaceMeetingUpdateDto) {
        log.info("修改功能场地：{}", SpaceMeetingUpdateDto);
        spaceMeetingService.update(SpaceMeetingUpdateDto);
        return Result.success();
    }

    //根据功能场地id查询功能场地详情
    @GetMapping("/{meetId}")
    @ApiOperation(value = "根据功能场地id查询功能场地详情")
    public  Result<SpaceMeetingVO> selectById(@PathVariable Long meetId) {
        log.info("根据功能场地id查询功能场地详情：{}",meetId);
        SpaceMeetingVO SpaceMeetingVO = spaceMeetingService.selectById(meetId);
        return Result.success(SpaceMeetingVO);
    }

    @GetMapping("/exportData")
    @ApiOperation(value = "导出功能场地数据")
    public void exportData(HttpServletResponse response){
        spaceMeetingService.exportData(response);
    }}
